//
//  WalletMeController.m
//  LiquorChain
//
//  Created by apple on 2019/1/7.
//  Copyright © 2019年 王冬. All rights reserved.
//

#import "WalletMeController.h"
#import "WalletViewCell.h"
#import "LiquorMarketController.h"

#define Start_X          60.0f      // 第一个按钮的X坐标
#define Start_Y          40.0f     // 第一个按钮的Y坐标
#define Width_Space      20.0f      // 2个按钮之间的横间距
#define Height_Space     10.0f     // 竖间距
#define Button_Height   22.0f    // 高
#define Button_Width    70.0f    // 宽

@interface WalletMeController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIButton *bottomBtn;
@property (nonatomic,strong) UIButton *selectedBtn;
@end

@implementation WalletMeController
static NSString *CellIdentifier = @"walletCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的钱包";
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, kNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kNavBarHeight-kIPhoneXBottomHeight-49) style:UITableViewStylePlain];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"WalletViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
    self.bottomBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.bottomBtn];
    [self.bottomBtn setTitle:@"出让圣酒" forState:UIControlStateNormal];
    [self.bottomBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.bottomBtn.titleLabel.font =[UIFont systemFontOfSize:15];
    self.bottomBtn.backgroundColor = RGB(249, 180, 59);
    [self.bottomBtn addTarget:self action:@selector(bottomClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-kIPhoneXBottomHeight);
        make.height.mas_equalTo(49);
    }];
    [self creatHeadView];
    // Do any additional setup after loading the view.
}
-(void)bottomClick:(UIButton *)sender{
    LiquorMarketController *liqoVC =[[LiquorMarketController alloc]init];
    [self.navigationController pushViewController:liqoVC animated:YES];
}
-(void)creatHeadView{
    
    UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 600)];
    headView.backgroundColor =[UIColor whiteColor];
    UIImageView *titleImageView = [[UIImageView alloc]init];
    titleImageView.userInteractionEnabled = YES;
    titleImageView.backgroundColor = RGB(249, 180, 59);
    [headView addSubview:titleImageView];
    [titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(234);
    }];
    UIImageView *headImageView =[[UIImageView alloc]init];
    headImageView.backgroundColor = [UIColor redColor];
    [titleImageView addSubview:headImageView];
    [headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.height.mas_equalTo(126);
        make.width.mas_equalTo(150);
        make.centerX.mas_equalTo(titleImageView.mas_centerX);
    }];
    UILabel *numberLabel =[[UILabel alloc]init];
    numberLabel.text =[NSString stringWithFormat:@"%@%f%@",@"我的圣酒 ",12.3445,@"滴"];
    numberLabel.textAlignment = NSTextAlignmentCenter;
    numberLabel.font =[UIFont systemFontOfSize:15];
    [titleImageView addSubview:numberLabel];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(headImageView.mas_bottom).with.offset(0);
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        make.height.mas_equalTo(14);
    }];
    
    
    UIButton *recordBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [titleImageView addSubview:recordBtn];
   [recordBtn setBackgroundColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.3]];
    recordBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [recordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(numberLabel.mas_bottom).with.offset(10);
        make.centerX.mas_equalTo(titleImageView.mas_centerX);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(20);
    }];
    recordBtn.layer.cornerRadius = 9;
    [recordBtn setTitle:@"圣酒记录" forState:UIControlStateNormal];
    [recordBtn setImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
    [recordBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:4];
    [recordBtn setTitleColor:[UIColor blackColor]
                   forState:UIControlStateNormal];
    [recordBtn addTarget:self action:@selector(recordClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *bodyView =[[UIView alloc]init];
    [headView addSubview:bodyView];
    bodyView.backgroundColor =[UIColor whiteColor];
    bodyView.layer.cornerRadius = 5;
    [bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(recordBtn.mas_bottom).with.offset(16);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(70);
        
    }];
    UILabel *infoLabel =[[UILabel alloc]init];
    [bodyView  addSubview:infoLabel];
    infoLabel.text = @"钱包地址asasasadsdadasdsa";
    infoLabel.font =[UIFont systemFontOfSize:12];
    infoLabel.textAlignment = NSTextAlignmentCenter;
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(12);
    }];
    UIButton *copyBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [bodyView addSubview:copyBtn];
    copyBtn.backgroundColor = RGB(249, 180, 59);
    [copyBtn setTitle:@"复制钱包地址" forState:UIControlStateNormal];
    [copyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    copyBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    copyBtn.layer.cornerRadius =9;
    [copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(infoLabel.mas_bottom).with.offset(12);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(20);
        make.centerX.mas_equalTo(bodyView.mas_centerX);
    }];
    UIView *bottomView =[[UIView alloc]init];
    [headView addSubview:bottomView];
    bottomView.backgroundColor =[UIColor whiteColor];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(bodyView.mas_bottom).with.offset(30);
        make.height.mas_equalTo(300);
    }];
    UILabel *linLabel  =[[UILabel alloc]init];
    [bottomView addSubview:linLabel];
    linLabel.text = @"圣酒兑换酒品走势图";
    linLabel.font = [UIFont systemFontOfSize:17];
    [linLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(20);
    }];
    
    NSArray *titleArray =@[@"近七日",@"近一月",@"近三月"];

    for (int i = 0 ; i < titleArray.count; i++) {
        NSInteger index = i % 3;
        NSInteger page = i / 3;
        
        // 圆角按钮
        UIButton *mapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [mapBtn setTitle:titleArray[i] forState:UIControlStateNormal];
        mapBtn.titleLabel.font =[UIFont systemFontOfSize:12];
        [mapBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [mapBtn setTitleColor:RGB(249, 180, 59) forState:UIControlStateSelected];
        mapBtn.layer.cornerRadius = 11;
        mapBtn.layer.borderWidth = 1;
        mapBtn.layer.borderColor = RGB(249, 180, 59).CGColor;
        mapBtn.tag = i;//这句话不写等于废了
        mapBtn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
        
        [bottomView addSubview:mapBtn];
        //按钮点击方法
        [mapBtn addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    //折线图
    
    
    
    UILabel *bottomLabel =[[UILabel alloc]init];
    bottomLabel.text = @"出让圣酒";
    [bottomView addSubview:bottomLabel];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-20);
        make.left.mas_equalTo(15);
        make.height.mas_equalTo(20);
    }];
    
    
    
    self.tableView.tableHeaderView = headView;
}
-(void)mapBtnClick:(UIButton *)sender{
    
    if (sender!= self.selectedBtn) {
        self.selectedBtn.selected = NO;
        sender.selected = YES;
        self.selectedBtn = sender;
    }else{
        self.selectedBtn.selected = YES;
    }
}
-(void)recordClick:(UIButton *)sender{
    NSLog(@"圣酒k记录");
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 110;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WalletViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //cell.textLabel.text = @"123";
    return cell;
}

@end
